namespace Mytodotodaylist.WF.Client.Views.MainView
{
    using System;
    using Core;
    using Core.Events;
    using Core.Notifications;

    public class MainPresenter : IObserver
    {
        public IMainView View;
        private INotificationService NotificationService;
        private readonly IEventRepository EventRepository;

        public MainPresenter(
            IMainView mainView, 
            INotificationService notificationService,
            IEventRepository eventRepository)
        {
            View = mainView;
            NotificationService = notificationService;
            EventRepository = eventRepository;

            NotificationService.AttachObserver(this);
            mainView.Initialise(this);

            Notify();
        }

        public void Notify()
        {
            View.ShowActiveNotifications(NotificationService.ActiveNotifications);
            View.ShowAllNotifications(NotificationService.AllNotifications);
        }

        public void AddEvent(Event theEvent)
        {
            EventRepository.Add(theEvent);
            NotificationService.LoadEvents();
        }

        public void UpdateEvent(Event theEvent)
        {
            EventRepository.Update(theEvent);
            NotificationService.LoadEvents();
        }

        public void DeleteEvent(Guid theEventId)
        {
            EventRepository.Delete(theEventId);
            NotificationService.LoadEvents();
        }
    }
}